package com.rede.didiok.common.config.mybatis;

import java.util.Collections;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;


/**
 * Mybatis-plus全局配置
 */
@EnableTransactionManagement
@Configuration
@MapperScan(basePackages = {
        "com.rede.didiok.admin.dao",
        "com.rede.didiok.user.dao",
        "com.rede.didiok.user.modulelist.rank.dao",
        "com.rede.didiok.user.modulelist.community.dao",
        "com.rede.didiok.user.modulelist.pay.dao",
        "com.rede.didiok.user.modulelist.file.dao",
//        "com.rede.didiok.community.dao",
        "com.rede.didiok.sms.task.mapper",
//        "com.rede.didiok.pay.dao",
})
public class MybatisPlusConfig {
    /**
     * 分页插件 3.5.X
     * @author zhengkai.blog.csdn.net
     */
    @Bean
    public PaginationInnerInterceptor paginationInnerInterceptor() {
        PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor();
        // 设置最大单页限制数量，默认 500 条，-1 不受限制
        paginationInterceptor.setMaxLimit(-1L);
        paginationInterceptor.setDbType(DbType.MYSQL);
        // 开启 count 的 join 优化,只针对部分 left join
        paginationInterceptor.setOptimizeJoin(true);
        return paginationInterceptor;
    }
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        mybatisPlusInterceptor.setInterceptors(Collections.singletonList(paginationInnerInterceptor()));
        return mybatisPlusInterceptor;
    }
}
